<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <link rel="stylesheet" href="../plugins/elementui/index.css">
</head>
<body>
<div id="app">

    <el-tree :data="treeData"
            show-checkbox
            node-key="id"
            default-expand-all
            :expand-on-click-node="false"
             indent="80">

      <span class="custom-tree-node" slot-scope="{ node, data }" >
<!--<span style="margin: 30px;">{{ data.label }}</span>-->
          <el-tag >{{ data.label }}</el-tag>

    <el-tooltip class="item" effect="dark" content="增加菜单" placement="top-start">
                <i class="el-icon-circle-plus-outline" @click="add(data,node)" ></i>
    </el-tooltip>
    <el-tooltip class="item" effect="dark" content="修改菜单" placement="top-start">
                <i class="el-icon-edit" @click="edit(data,node)" ></i>
    </el-tooltip>
    <el-tooltip class="item" effect="dark"  content="删除菜单" placement="top-start">
                <i class="el-icon-delete" @click="delete1(data,node)" ></i>
    </el-tooltip>

      </span>
    </el-tree>



    <el-dialog title="菜单信息" :visible.sync="dialogFormVisible">
        <h3>菜单名</h3>
        <el-input v-model="formData.name"></el-input>
        <h3>跳转页面URL</h3>
        <el-input v-model="formData.linkUrl"></el-input>
        <h3>描述</h3>
        <el-input v-model="formData.description"></el-input>
        <br>
        <br>
        <br>
        <el-button type="primary" @click="doAdd">确 定</el-button>
        <el-button type="primary" @click="cancel">取 消</el-button>
    </el-dialog>

    <el-dialog title="菜单信息" :visible.sync="dialogForm4Edit">
        <h3>菜单名</h3>
        <el-input v-model="formData.name"></el-input>
        <h3>跳转页面URL</h3>
        <el-input v-model="formData.linkUrl"></el-input>
        <h3>描述</h3>
        <el-input v-model="formData.description"></el-input>
        <br>
        <br>
        <br>
        <el-button type="primary" @click="doEdit">确 定</el-button>
        <el-button type="primary" @click="cancel">取 消</el-button>
    </el-dialog>


</div>


<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script>
    var vm  = new Vue({
        el:"#app",
        data:{
            dialogFormVisible:false,
            dialogForm4Edit:false,
            treeData:[],
            formData:{}
        },
        methods:{
            add(data,node){

                //弹出新增框架
                this.formData.level=node.level;
                this.dialogFormVisible = true;
                this.formData.parentMenuId = data.id;
            },
            doAdd(){
                axios.post("/test/addMenu.do",this.formData).then((res)=>{
                    //刷新页面
                    this.dialogFormVisible = false;
                    this.findPage();
                })
            },
            findPage(){
                axios.get("/test/getAllMenu.do").then((res)=>{
                    this.treeData = res.data.data;
                })
            },
            edit(data){
                this.formData.id = data.id;
                axios.post("/test/edit.do",this.formData).then((res)=>{
                    this.formData = res.data.data;
                    this.dialogForm4Edit = true;
                })
            },
            cancel(){
                this.dialogForm4Edit = false;
                this.dialogFormVisible = false;
            },
            doEdit(){
                axios.post("/test/doedit.do",this.formData).then((res)=>{
                    //刷新页面
                    this.dialogFormVisible = false;
                    this.findPage();
                })
            },
            delete1(data,node){
                this.$confirm('是否确认删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.delete("/test/deletebyid.do",{params:{id:data.id}}).then((res) => {
                        if (res.data.flag) {
                            this.findPage();
                        }
                        //弹出提示
                        this.$message({
                            message: res.data.message,
                            type: res.data.flag ? 'success' : 'error'
                        });
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        },
        created(){
            this.findPage();
        }

    })


    //{data:[]}

</script>
</body>
</html>
